Get Package
Description
The get_package
function retrieves information about a specific package from the web service using its package ID. It returns a WebServiceResult
object that contains the server's response.
Function Signature:
def get_package(ws_config: WebServiceConfig, package_id: int) -> WebServiceResult:
Parameters
- ws_config (WebServiceConfig): Configuration object for the web service.
- package_id (int): The ID of the package to be retrieved.
Returns
- WebServiceResult: The result of the web service request, including:
- http_response_code: HTTP response status (e.g., 200 for success).
- http_response_string: Raw response from the server.
- json_data: Parsed JSON content from the response, if available.
Example Usage
ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
package_id = 101
result = get_package(ws_config, package_id)
print(result.http_response_code, result.json_data)
Behavior
- Sends a
GET
request to the server to retrieve package metadata using the providedpackage_id
. - On a successful response, returns package details as part of the parsed JSON response.
- Wraps the result in a
WebServiceResult
object for consistent handling.
Error Handling
- General Exception: If an error occurs during the request or processing, the function logs the error, sets the response code to
-1
, and provides a description of the error in the result.